﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace NMigrate
{
	public class TemplateSpecification
	{
		public Encoding Encoding
		{
			get;
			set;
		}
	}
	public class TemplateInfo
	{
		public FileInfo InitialFile
		{
			get;
			internal set;
		}
		public bool Templated
		{
			get;
			internal set;
		}
		public FileInfo TemplatedFile
		{
			get;
			internal set;
		}
	}
	public abstract class FileHandler
	{
		public virtual bool CanExecute(FileInfo file)
		{
			if(!String.IsNullOrEmpty(Extension))
			{
				return file.Extension == ExtensionWithPoint;
			}
			throw new InvalidOperationException(this.GetType().Name + " should at least implements Extension property or CanExecute method");
		}


		public virtual string Extension
		{
			get
			{
				return null;
			}
		}

		string _ExtensionWithPoint;
		public string ExtensionWithPoint
		{
			get
			{
				if(_ExtensionWithPoint == null)
				{
					_ExtensionWithPoint = Extension;
					if(_ExtensionWithPoint.StartsWith("."))
						return _ExtensionWithPoint;
					_ExtensionWithPoint = "." + _ExtensionWithPoint;
				}
				return _ExtensionWithPoint;
			}
		}


		public virtual void Execute(FileInfo file, TemplateInfo templateInfo, Configuration args)
		{
			Execute(file, args);
		}

		public abstract void Execute(FileInfo file, Configuration args);

		public abstract bool IsTemplated(FileInfo file);

		public virtual TemplateSpecification GetTemplateSpecification(FileInfo file)
		{
			if(IsTemplated(file))
				return new TemplateSpecification();
			return null;
		}

	}
}
